# -*- coding: utf-8 -*-
"""
Created on Sun Jun 10 14:20:01 2012

@author: nzhao
"""
from traits.api import HasTraits, Instance, List, Int, Button
from traitsui.api import View, Group, Item

import numpy as np

from math_qm.CoordianteSystem import CoordinateSystem


axes_group = Group( 
                Group(
                    Item('axes0', style='custom'),
                    label='Natural axes',
                    show_border=True
                    ),
                Group(
                    Item('axes1', style='custom'),
                    label='Crystal axes',
                    show_border=True
                    ),
                Group(
                    Item('axes2', style='custom'),
                    Item('axes2X'),
                    label='custom 1',
                    show_border=True
                    ),
                Group(
                    Item('axes3', style='custom'),
                    label='custom 2',
                    show_border=True
                    ),                    
                label='Axes'
                )
                
class Axes(HasTraits):
    axes0 = Instance(CoordinateSystem)
    axes1 = Instance(CoordinateSystem)
    axes2 = Instance(CoordinateSystem)
    axes3 = Instance(CoordinateSystem)
    axes_list = List( CoordinateSystem )
    num_axes  = Int(4)
    
    axes2X = Button
    
    def _axes2X_fired(self):
        ax = np.cross(np.array([0., 0. ,1.]), self.axes2.x_axis)
        self.axes2.y_axis = ax / np.linalg.norm(ax)
        self.axes2.z_axis = np.cross(self.axes2.x_axis,      self.axes2.y_axis)
    
    def __init__(self):
        self.axes0 = CoordinateSystem()
        self.axes1 = CoordinateSystem(  x_axis = np.array([1., -1.,  0.0]) / np.sqrt(2.0), \
                                        y_axis = np.array([1.,  1., -2.0]) / np.sqrt(6.0), \
                                        z_axis = np.array([1.,  1.,  1.0]) / np.sqrt(3.0) )
        self.axes2 = CoordinateSystem( )      
        self.axes3 = CoordinateSystem( )
        
        self.axes0.name = 'nature'
        self.axes1.name = 'crystal'
        self.axes2.name = 'custom1'
        self.axes3.name = 'custom2'
        
        self.axes_list = [self.axes0, self.axes1, self.axes2, self.axes3]
        
    axes_view = View(
        axes_group,
        title     = 'Axes',
        width     = .8,
        height    = .9,
        resizable = True,
        buttons   = [ 'OK' ],
        kind      = 'live'
    )

        


if __name__ == '__main__':
    ax=Axes()
    ax.configure_traits()